//处理更新
const db=require("../lib/db")

function updateIdArticle(id,title,content,desc,author,authorId,classify){
    return new Promise((resolve,reject)=>{
        let sql=`update article set title='${title}',content='${content}',\`desc\`='${desc}' ,author='${author}', authorId=${authorId}, classify='${classify}' where id=${id}`
        console.log(sql)
        db.querySql(sql)
        let sql2=`select * from article where id=${id};`
        db.querySql(sql2).then(data=>{
            if(data.length==0){
                resolve(404)
            }else{
                let arr=[]
                data.map(element=>{
                    arr.push({
                        author: element.author,
                        authorId: element.authorId,
                        classify: element.classify,
                        content: element.content,
                        desc: element.desc,
                        time: element.time,
                        title: element.title,
                        __v: 0,
                        _id: Buffer.from(String(element.id)).toString("Base64")                                                                                                                   
                    })
                })
                console.log(arr)
                resolve(arr)
            }
        })
    })
}

module.exports=updateIdArticle;